define(["storage"], function(myStorage) {
	var login_tool = {}
	/*
	 	获取当前时间戳
	 * */
	login_tool.get_utc = function() {
		var timestamp = Date.parse(new Date());
		return timestamp / 1000;
	}

	/*
	  	获取accesstoken
	 * */
	login_tool.OnGetAccessToken = function() {
		var obj = myStorage.getItem("accesstoken")
		console.log(JSON.stringify(obj))
		now = login_tool.get_utc();
		if(obj != null && obj.expire_time > now) {
			return obj.access_token;
		} else {
			return ""
		}
	}

	return login_tool;
})

//define(function(){
//	
//})

//获取手机imei
function getuuid() {
	return plus.device.imei
}

//深拷贝
function cloneObj() {

	var newObj = {}

	for(var prop in obj) {
		newObj[prop] = obj[prop]
	}

	return newObj
}

//创建界面
var _openw = null;
var wating;

function toCreateNew(_url, _id, _styles, _param) {
	if(_openw == null) {
		_openw = true;
		wating = plus.nativeUI.showWaiting("加载中...");
		_this = this;
		creatNewPage(_url, _id, _styles, _param) //这个函数在common.js 是创建页面的函数,主要功能,创建页面,避免重复创建
	} else {
		return
	}
}

/*
 * 创建页面
 * url:页面路径
 * id：页面id
 * styles：页面的样式
 * extras：向新页面传的参数
 * */
function creatNewPage(_url, _id, _styles, _extras) {
	console.log(_url)
	var newPage = plus.webview.create(_url, _id, _styles, _extras);
	newPage.addEventListener("loaded", function() {
		wating.close()
		newPage.show("pop-in", 300, function() {
			_openw = null;
			console.log(_openw)
		});
	});

}

//未登录前往登录页面
function tologin(_url, _id) {
	var login = plus.webview.create(_url, _id);
	login.addEventListener("loaded", function() {
		login.show("pop-in", 300);
	})
}

//显示loading
var ownmask;

function showMask() {
	ownmask = plus.nativeUI.showWaiting("加载中...");
}

function closeMask() {
	ownmask.close();
}

var tipbacki = 0 //退出初始参数0

function back() {
	mui.back = function() {
		tipbacki = tipbacki + 1;
		console.log(tipbacki)
		if(tipbacki == 1) {
			mui.toast("再按一次,退出程序");
		} else if(tipbacki == 2) {
			plus.runtime.quit();
		}
		setTimeout(function() {
			tipbacki = 0;
		}, 1500)
	}
}

/*
 *检测手机平台
 * 
 * */
var judgePlatform = (Android, iOS, other) => {
	switch(plus.os.name) {
		case "Android":
			// Android平台: plus.android.*
			Android || Android();
			break;
		case "iOS":
			// iOS平台: plus.ios.*
			iOS || iOS();
			break;
		default:
			// 其它平台
			other || other();
			break;
	}
}

//上拉加载是否结束
//function upOver(data) {
//	if(data == null || data == false) {
//		mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
//		return false;
//	} else {
//		mui('#pullrefresh').pullRefresh().endPullupToRefresh(false)
//	}
//}
//
//function toOrderDetail() {
//	var order_id = this.getAttribute("order_id");
//	if(_openw == null) {
//		_openw = true;
//		wating = plus.nativeUI.showWaiting("加载中...")
//		_this = this;
//		creatNewPage("order_detail.html", "order_detail.html", {}, {
//			order_id: order_id
//		})
//	} else {
//		return
//	}
//}
//
//function uploadFile(local_url,server,callback) {
//	var task = plus.uploader.createUpload(server, {method: "POST"},callback);
//	task.addFile(local_url, {
//		key: 'upload_info'
//	});
//	task.start();
//}